package com.ssm.springboot.controller;

import com.ssm.springboot.pojo.DataInfo;
import com.ssm.springboot.pojo.TbRole;
import com.ssm.springboot.pojo.req.UpdateRoleRes;
import com.ssm.springboot.pojo.req.UpdateUserRoleRes;
import com.ssm.springboot.service.TbRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TbRole)表控制层
 *
 * @author makejava
 * @since 2021-12-27 22:29:21
 */
@RestController
@RequestMapping("/tbRole")
public class TbRoleController {
    /**
     * 服务对象
     */
    @Resource
    private TbRoleService tbRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequiresPermissions(value = {"/tbRole/selectOne"})
    @GetMapping("/selectOne")
    public TbRole selectOne(Integer id) {
        return this.tbRoleService.queryById(id);
    }
    @RequiresPermissions(value = {"/tbRole/add"})
    @RequestMapping("/add")
    public DataInfo add(@RequestBody TbRole tbRole){
        return tbRoleService.add(tbRole);
    }


    @RequestMapping("/findAll")
    @RequiresPermissions(value = {"/tbRole/findAll"})
    public DataInfo findAll(@RequestParam("page") int page,@RequestParam("limit") int limit){
        return tbRoleService.queryAllByLimit(page,limit);
    }

    //查询角色权限
    @RequiresPermissions(value = {"/tbRole/findByRoleid"})
    @RequestMapping("/findByRoleid")
    public DataInfo findByRoleid(int roleid){
        return tbRoleService.findByRoleid(roleid);
    }

    //更新角色权限
    @RequestMapping("/updateRole")
    @RequiresPermissions(value = {"/tbRole/updateRole"})
    public DataInfo updateRole(@RequestBody UpdateRoleRes updateRoleRes){
        return tbRoleService.tbRoleService(updateRoleRes);
    }
    //查询用户角色
    @RequiresPermissions(value = {"/tbRole/findByUserid"})
    @RequestMapping("/findByUserid")
    public DataInfo findByUserid(Integer userid){
        return tbRoleService.findByUserid(userid);
    }
    //更新用户角色
    @RequiresPermissions(value = {"/tbRole/updateUserRole"})
    @RequestMapping("/updateUserRole")
    public DataInfo updateUserRole(@RequestBody UpdateUserRoleRes updateRoleRes){
        System.out.println(updateRoleRes);
        return tbRoleService.updateUserRole(updateRoleRes);
    }

}